<?php
namespace app\finance\controller;

use app\main\controller\BaseController;
use app\finance\model\Journal;

class JournalController extends BaseController 
{
    public function indexAction() 
    {
        $items = new Journal();
        $users = $items->findAll();
        // $this->render('view/journal/index', ['items'=>$items]);
    }

    public function addAction() 
    {
        if($_SERVER['REQUEST_METHOD']==='POST') {
            $this->model->insert($_POST);
            header('Location: /finance/journal/index'); exit;
        }
        $this->render('view/journal/form');
    }

    public function editAction($id) 
    {
        $itemData = $this->model->get($id);
        if($_SERVER['REQUEST_METHOD']==='POST') {
            $this->model->update($id, $_POST);
            header('Location: /finance/journal/index'); exit;
        }
        $this->render('view/journal/form', ['item'=>$itemData]);
    }

    public function deleteAction($id) 
    {
        $this->model->delete($id);
        header('Location: /finance/journal/index'); exit;
    }
}
